import QtQuick 2.12
import QtQuick.Window 2.3

Item {
    id: container

    property alias text: buttonLabel.text
    property alias label: buttonLabel
    signal clicked
    property alias containsMouse: hoverHandler.hovered
    property alias pressed: tapHandler.pressed

    property color textColor: "#FFFFFF"
    property color backgroundColor: "#FF8686"

    implicitHeight: Math.max(Screen.pixelDensity * 4, buttonLabel.implicitHeight * 0.8)
    implicitWidth: Math.max(Screen.pixelDensity * 11, buttonLabel.implicitWidth * 1.3)
    height: implicitHeight
    width: implicitWidth

    onPressedChanged: {
        container.scale = pressed ? 0.99 : 1.0
    }

    Rectangle {
        id: frame
        anchors.fill: parent
        antialiasing: true

        property color bgColor: container.enabled ? backgroundColor : "#999"

        gradient: Gradient {
            orientation: Gradient.Horizontal
            GradientStop { position: 0.0; color: frame.bgColor }
            GradientStop { position: 1.0; color: Qt.lighter(frame.bgColor, 1.3) }
        }
    }

    TapHandler {
        id: tapHandler
        onTapped: container.clicked();
    }
    HoverHandler {
        id: hoverHandler
    }

    Text {
        id: buttonLabel
        text: container.text
        color: container.textColor
        font.pixelSize: container.height * 0.35
        anchors.centerIn: parent
    }
}
